﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.DALFactory;
using KPIS.GERP.GHRMS.IBLL;

namespace KPIS.GERP.GHRMS.BLL
{
    public sealed class MasCountryBLL : IMasCountryBLL
    {
        private static readonly IMasCountryDAL dal = DataAccess.CreateMasterCountry();

        private MasCountryZoneInfo zoneInfo = new MasCountryZoneInfo();
        private MasCountryInfo countryInfo = new MasCountryInfo();

        public DataSet LoadMasCountries(Nullable<int> Sequence, Nullable<int> ZoneSequence)
        {
            MasCountryInfo cInfo = new MasCountryInfo();
            MasCountryZoneInfo zInfo = new MasCountryZoneInfo();

            cInfo.Sequence = Sequence.HasValue ? Sequence : 0;
            if (ZoneSequence.HasValue)
            {
                zInfo.Sequence = ZoneSequence;
                cInfo.CountryZones = zInfo;
            }
            return dal.LoadMasCountries(cInfo);
        }
         
        public IList<MasCountryInfo> ListMasCountries()
        {
            return dal.ListMasCountries(new MasCountryInfo(0));
        }
        public IList<MasCountryInfo> ListMasCountries(string Sequence, string Zone)
        {
            int Seq = Sequence.Length > 0 ? Int32.Parse(Sequence) : 0;
            zoneInfo.Sequence = Zone.Length > 0 ? Int32.Parse(Zone) : 0;
            return dal.ListMasCountries(new MasCountryInfo(Seq, "", "", "", zoneInfo, "", 0, 0));
        }
        public void Insert(string Code, string Name, string NameEng, string Remarks, int CountryZone, int CreatedBy)
        {
            zoneInfo.Sequence = CountryZone;

            try
            {
                dal.Insert(new MasCountryInfo(0, Code, Name, NameEng, zoneInfo, Remarks, CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }

        }
        public void Update(int Sequence, string Code, string Name, string NameEng, string Remarks, int CountryZone, int UpdatedBy)
        {
            zoneInfo.Sequence = CountryZone;

            try
            {
                dal.Update(new MasCountryInfo(Sequence, Code, Name, NameEng, zoneInfo, Remarks, 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }

        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                dal.Delete(new MasCountryInfo(Sequence, "", "", "", zoneInfo, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }

        }
        public void UpdateZones(int Sequence, int CountryZone, int UpdatedBy)
        {
            zoneInfo.Sequence = CountryZone;

            try
            {
                dal.Insert(new MasCountryInfo(Sequence, "", "", "", zoneInfo, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }

        }
    }
}
